#pragma once

#include "util/types.h"
#include "feature/matching.h"
#include "base/reconstruction.h"

#include <vector>
#include <string>
#include <memory>
#include <flann/flann.hpp>

bool createDatabaseFromProject(const std::string& idx_path, const std::string& calib_path, const std::string& database_path);
void extractFeatures(const std::string& image_dir, const std::string& database_path);
void matchFeatures(const std::string& database_path, double radius, double theta);

flann::Index<flann::L2<float>> buildKDTree(const std::vector<std::vector<float>>& data_points, int dimensions, int tree_num = 1);
float euclideanDistance(const std::vector<float>& point1, const std::vector<float>& point2);

void matchFeaturesPointcloud(const std::string& database_path, const std::string& points_path, 
    colmap::image_t image_id1, colmap::image_t image_id2, float radius, 
    colmap::FeatureMatches& matches, std::vector<Eigen::Vector3d>& points3d);

void saveToIdx(colmap::Reconstruction& model, const std::string& idx_path);

